/***
 * 富文本的工具栏封装
 * @Author: kevin.huang 
 * ****/
function Toolbars(edit) {
    $B.extend(this, Toolbars); //继承父类 
    this.edit = edit;
    this.$wrap = $("<div tabindex='0' style='z-index:2' class='k_box_size k_edit_tools_wrap'></div>").appendTo(edit.jqObj);
    this.opts = edit.opts;
    var _this = this;
    this.buttons = {};
    var models = this.opts.tools ? this.opts.tools : eConfig.tools;
    this.toolbarStyle = this.edit.opts.toolbarStyle;
    var hideMouseIt = {
        insertTable: true,
        showInsertImageWindow: true,
        showInsertFileWindow: true,
        link: true,
        showEmotionWindow: true
    };
    Object.keys(models).forEach(function (key) {
        var title = models[key];
        var go = true;
        if (key === "mobile") {//非移动适配模式
            go = edit.opts.mobile;
        }
        if (go) {
            var it = config.tools[key];
            if (it) {
                it.title = title;
                _this.createTool(it, key);
                if (key === "insertTable") {
                    hideMouseIt.insertTable = false;
                } else if (key === "link") {
                    hideMouseIt.link = false;
                } else if (key === "picture") {
                    hideMouseIt.showInsertImageWindow = false;
                } else if (key === "upload") {
                    hideMouseIt.showInsertFileWindow = false;
                } else if (key === "emotion") {
                    hideMouseIt.showEmotionWindow = false;
                }
            }
        }
    });
    //版本说明    
    _this.createTool({icon: "fa-info-circled", params: {undo:false,needRange:false}, title: eConfig.label.version},"showVersion");
    this.edit.defaultHideMouseIts = [];//根据配置隐藏鼠标右键菜单对应的项目
    window["_bui_"]=true;
    Object.keys(hideMouseIt).forEach(function (key) {
        if (hideMouseIt[key]) {
            _this.edit.defaultHideMouseIts.push(key);
        }
    });
    this.tip = $("<div style='width:auto;max-width:120px;position:absolute;top:-500px;' class='k_edit_tools_tip_wrapper' disabled='disabled'><div class='k_edit_tools_tip_caret'><i style='height:5px;' class='fa fa-up-dir'></i></div><div class='k_edit_tools_tip_text'></div></div>").appendTo(_getBody()).hide();
    this.$wrap.mouseleave(function (e) {
        if ($(e.target).hasClass("k_edit_tools_wrap")) {
            _this.hideTip();
            _this._hideDropList();
        }
    }).on("click", function (e) {
        _this.hideTip();
        _this._hideAllDropList();
    }).focus(function () {
        _this.edit.rebuildUserRange();
    });
    this.tip.mouseleave(function () {
        _this.hideTip();
    });
    //颜色控件
    this.ColorPickerPanel = new $B.ColorPicker(undefined, {
        update2Target: false,
        showCaret: true,
        positionFix: {
            top: 2,
            left: 1
        },
        onfocus: function () {
            _this.edit.rebuildUserRange();
        },
        mouseenter: function () {
            clearTimeout(_this.hideDropDownListTimer);
        },
        change: function (val) {
            var $t = _this.currentClickBtn;
            var method = $t.data("method");
            var params = $t.data("params");
            if (typeof params === "undefined") {
                params = {};
            }
            params["color"] = val;
            _this.edit.execute(method, params);
            $t.children("h1").css("background", val);
        },
        onStartFn: function () {
            _this.edit._makeUndoDataByFocus();
        }
    });
    this.ColorPickerPanel["name"] = "kedit main ColorPicker";
    this.ColorPickerPanel.setValue({
        hex: "#051F7C"
    });
    this.ColorPickerPanel.jqObj.addClass("k_edit_panel_border_top");
    this.allPanels = {
        "ColorPickerPanel": this.ColorPickerPanel
    };
}
Toolbars.prototype = {
    constructor: Toolbars,
    destroy: function () {
        var _this = this;
        Object.keys(_this.allPanels).forEach(function (key) {
            if (key !== "ColorPickerPanel") {
                _this.allPanels[key].remove();
            }
        });
        this.tip.remove();
        this.ColorPickerPanel.destroy(this);
        this.super.destroy.call(this);
    },
    hideTip: function (t) {
        this.tip.hide();
    },
    /**点击事件监听
     * 收起下拉框，修饰联动
     * ***/
    clickSubscribe: function (edit, rangeCss) {
        this._hideDropList();
        this.hideTip();
        var i, len, item;
        var titleBtn = this.buttons["fontTitle"];
        //console.log(" clickSubscribe  >>>> clickSubscribe");
        var titleTxt = titleArray[0].txt;
        if (rangeCss.fontTitle) {
            var f = rangeCss.fontTitle;
            for (i = 0, len = titleArray.length; i < len; ++i) {
                item = titleArray[i];
                if (item.v["font-size"] === f["font-size"] && item.v["font-weight"] === f["font-weight"]) {
                    titleTxt = item.txt;
                    break;
                }
            }
        }
        if (titleBtn) {
            titleBtn.children("span").text(titleTxt);
        }
        var boldBtn = this.buttons["bold"];
        if (boldBtn) {
            if (rangeCss["font-weight"] && rangeCss["font-weight"] === "700") {
                boldBtn.addClass("k_edit_tools_item_actived");
            } else {
                boldBtn.removeClass("k_edit_tools_item_actived");
            }
        }

        var italicBtn = this.buttons["italic"];
        if (italicBtn) {
            if (rangeCss["font-style"] && rangeCss["font-style"] === "italic") {
                italicBtn.addClass("k_edit_tools_item_actived");
            } else {
                italicBtn.removeClass("k_edit_tools_item_actived");
            }
        }

        var underlineBtn = this.buttons["underline"];
        if (underlineBtn) {
            if (rangeCss["text-decoration"] && rangeCss["text-decoration"].indexOf("underline") > -1) {
                underlineBtn.addClass("k_edit_tools_item_actived");
            } else {
                underlineBtn.removeClass("k_edit_tools_item_actived");
            }
        }
        var strikethroughBtn = this.buttons["strikethrough"];
        if (strikethroughBtn) {
            if (rangeCss["text-decoration"] && rangeCss["text-decoration"].indexOf("line-through") > -1) {
                strikethroughBtn.addClass("k_edit_tools_item_actived");
            } else {
                strikethroughBtn.removeClass("k_edit_tools_item_actived");
            }
        }
        var verticalAlign = rangeCss["vertical-align"];
        var superscriptBtn = this.buttons["superscript"];
        if (superscriptBtn) {
            if (verticalAlign && verticalAlign === "super") {
                superscriptBtn.addClass("k_edit_tools_item_actived");
            } else {
                superscriptBtn.removeClass("k_edit_tools_item_actived");
            }
        }
        var subscriptBtn = this.buttons["subscript"];
        if (subscriptBtn) {
            if (verticalAlign && verticalAlign === "sub") {
                subscriptBtn.addClass("k_edit_tools_item_actived");
            } else {
                subscriptBtn.removeClass("k_edit_tools_item_actived");
            }
        }

        var fontFamilyBtn = this.buttons["fontFamily"];
        var fontFamily = rangeCss["font-family"];
        if (fontFamilyBtn) {
            if (fontFamily) {
                fontFamily = fontFamily.toLowerCase().replace(/,\s*/g, ",").replace(/"/g, "");
                for (i = 0, len = fontsFamilyMap.length; i < len; ++i) {
                    item = fontsFamilyMap[i];
                    if (item.v.toLowerCase().indexOf(fontFamily) >= 0) {
                        fontFamilyBtn.children("span").text(item.txt);
                        break;
                    }
                }
            } else {
                for (i = 0, len = fontsFamilyMap.length; i < len; ++i) {
                    item = fontsFamilyMap[i];
                    if (item.v.toLowerCase().indexOf(defaultStyleObject["font-family"]) >= 0) {
                        fontFamilyBtn.children("span").text(item.txt);
                        break;
                    }
                }
            }
        }

        var fontSizeBtn = this.buttons["fontSize"];
        if (fontSizeBtn) {
            var fsize = rangeCss["font-size"];
            if (fsize) {
                for (i = 0, len = fontsMap.length; i < len; ++i) {
                    item = fontsMap[i];
                    if (item.v.toLowerCase().indexOf(fsize) >= 0) {
                        fontSizeBtn.children("span").text(item.txt);
                        break;
                    }
                }
            }
        }
        var fontColorBtn = this.buttons["fontColor"];
        if (fontColorBtn) {
            var color = rangeCss["color"];
            fontColorBtn.children("h1").css("background", color);
        }
        var backgroundColorBtn = this.buttons["backgroundColor"];
        if (backgroundColorBtn) {
            var bColor = rangeCss["background-color"];
            backgroundColorBtn.children("h1").css("background-color", bColor);
        }
        // var orderListBtn = this.buttons["orderList"];
        // var unorderListBtn = this.buttons["unorderList"];
        var alignCenterBtn = this.buttons["alignCenter"];
        var alignLeftBtn = this.buttons["alignLeft"];
        var alignRightBtn = this.buttons["alignRight"];
        var textAlign = rangeCss["text-align"];
        if (alignCenterBtn) {
            if (textAlign === "center") {
                alignCenterBtn.addClass("k_edit_tools_item_actived");
            } else {
                alignCenterBtn.removeClass("k_edit_tools_item_actived");
            }
        }
        if (alignLeftBtn) {
            if (textAlign === "left" || textAlign === "start") {
                alignLeftBtn.addClass("k_edit_tools_item_actived");
            } else {
                alignLeftBtn.removeClass("k_edit_tools_item_actived");
            }
        }
        if (alignRightBtn) {
            if (textAlign === "right") {
                alignRightBtn.addClass("k_edit_tools_item_actived");
            } else {
                alignRightBtn.removeClass("k_edit_tools_item_actived");
            }
        }
    },
    _dropDownControlMouseenter: function (e) {
        clearTimeout(e.data.seft.hideDropDownListTimer);
    },
    /**关闭所有下来列表***/
    _hideAllDropList: function () {
        var _this = this;
        Object.keys(_this.allPanels).forEach(function (key) {
            _this.allPanels[key].hide();
        });
    },
    /**关闭列表
     * handler：对应的处理函数名称，去掉show即为panel的key
     * **/
    _hideDropList: function (handler) {
        handler = handler ? handler : '';
        var timer = 200;
        if (handler !== "") {
            timer = 0;
        }
        var _this = this;
        function a() {
            var panelObjName = handler.replace("show", "");
            Object.keys(_this.allPanels).forEach(function (key) {
                if (key !== panelObjName) {
                    _this.allPanels[key].hide();
                }
            });
        }
        if (timer > 0) {
            _this.hideDropDownListTimer = setTimeout(function () {
                a();
            }, timer);
        } else {
            a();
        }
    },
    _focus: function () {
        $(this).data("self").edit.rebuildUserRange();
        return false;
    },
    /**调用edit对应的处理API
     * 如果有handler参数则先调用toolbar的handler，handler里面再调用edit的处理api
     * 这里是工具栏通向edit的入口
     * **/
    _click: function () {
        var $t = $(this);
        var _this = $t.data("self");
        if (_this.edit.activedMenu && _this.edit.activedMenu[0] !== this) {
            _this.edit.activedMenu.removeClass("k_edit_btn_actived");
            _this.edit.brushCss = undefined;
        }
        _this.tip.hide();
        var handler = $t.data("handler");
        _this._hideDropList(handler);
        _this.currentClickBtn = $t;
        if ($t.hasClass("k_edit_tools_disabled")) {
            return false;
        }
        var method = $t.data("method");
        var params = $t.data("params");
        if (typeof params === "undefined") {
            params = {};
        }
        //如果存在handler则执行handler，由handler里面再调用edit.execute
        if (typeof _this[handler] === "function") {
            _this[handler](method, params, $t);
        } else {
            _this.edit.execute(method, params, $t);
        }
        return false;
    },
    createTool: function (it, key, borderColor) {      
        var _this = this;
        var height;
        var btn = $("<div key='" + key + "' style='padding-bottom:2px;cursor:pointer;position:relative;border:1px solid " + borderColor + "' tabindex='0' _title='" + it.title + "' class='k_box_size k_edit_tools_item'><i class='fa " + it.icon + "'></i></div>");
        if (this.toolbarStyle) {
            // btn.children("i").css(this.toolbarStyle);
            // btn.css("line-height","1.3em");
            btn.addClass("k_edit_toolbar_style");
            if (this.toolbarStyle.margin) {
                btn.css("margin", this.toolbarStyle.margin);
            }
            if (this.toolbarStyle.size) {
                btn.css({ "height": this.toolbarStyle.size });
            }
            var style = '.k_edit_toolbar_style {line-height:1.3em;}';
            style = style + '.k_edit_toolbar_style i {font-size:' + this.toolbarStyle["font-size"] + ';color:' + this.toolbarStyle["color"] + ';}';
            style = style + ".k_edit_tools_disabled i {color: #ccc !important;cursor: not-allowed;} .k_edit_btn_actived i {color: red  !important;}";
            head.children("#k_edit_diy_toolbar").remove();
            head.append("<style id='k_edit_diy_toolbar'>" + style + "</style>");
        }
        btn.appendTo(this.$wrap).mouseover(function (e) {
            var $t = $(this);
            var ofs = $t.offset();
            var title = $t.attr("_title");
            _this.tip.css({
                top: ofs.top + height,
                left: ofs.left
            });
            _this.tip.children(".k_edit_tools_tip_text").text(title);
            _this.tip.show();          
        }).mouseleave(function (e) {
            if ($(e.target).hasClass("k_edit_tools_item")) {
                //console.log(" mouseout mouseout mouseout");
                // _this.hideTip();
                //_this.tip.hide();
                //_this._hideDropList();
            }
            return false;
        }).data("method", key)
            .data("handler", it.click)
            .data("params", it.params)
            .data("self", _this);
        if (it.disabled) {
            btn.addClass("k_edit_tools_disabled");
        }
        btn.on("focus", _this._focus);
        btn.on("click", _this._click);
        height = btn.height();
        this.buttons[key] = btn;
        var i, len, item;
        if (key === "fontFamily") {
            for (i = 0, len = fontsFamilyMap.length; i < len; ++i) {
                item = fontsFamilyMap[i];
                if (item.v.toLowerCase().indexOf(defaultStyleObject["font-family"]) >= 0) {
                    btn.prepend("<span>" + item.txt + "</span>");
                    break;
                }
            }
        } else if (key === "fontTitle") {
            btn.prepend("<span>" + titleArray[0].txt + "</span>");
        } else if (key === "fontSize") {
            for (i = 0, len = fontsMap.length; i < len; ++i) {
                item = fontsMap[i];
                if (item.v.toLowerCase().indexOf(defaultStyleObject["font-size"]) >= 0) {
                    btn.prepend("<span>" + item.txt + "</span>");
                    break;
                }
            }
        } else if (key === "fontColor") {
            btn.append("<h1 class='k_box_size' style='bottom: -3px;position:absolute;border: 1px solid rgb(204, 204, 204);width:100%;height:4px;margin:0px;padding:0;background:" + defaultStyleObject["color"] + "'></h1>");
        } else if (key === "backgroundColor") {
            btn.append("<h1 class='k_box_size' style='bottom: -3px;position:absolute;border: 1px solid rgb(204, 204, 204);width:100%;height:4px;margin:0px;padding:0;background:" + defaultStyleObject["background-color"] + "'></h1>");
        }
        return btn;
    },
    notifyTools: function (args) {
        var operator = args["operator"];
        var params = args["params"];
        if (this[operator + "Notify"]) {
            this[operator + "Notify"](params);
        }
    },
    _changeUndoRedoBtns: function (params) {
        if (params.undoStackSize === 0) {
            this.buttons["undo"].addClass("k_edit_tools_disabled");
        } else {
            this.buttons["undo"].removeClass("k_edit_tools_disabled");
        }
        if (params.redoStackSize === 0) {
            this.buttons["redo"].addClass("k_edit_tools_disabled");
        } else {
            this.buttons["redo"].removeClass("k_edit_tools_disabled");
        }
    },
    redoNotify: function (params) {
        this._changeUndoRedoBtns(params);
    },
    undoNotify: function (params) {
        this._changeUndoRedoBtns(params);
    },
    _onfocus: function () {
        var seft = $(this).data("seft");
        if (seft) {
            seft.edit.rebuildUserRange();
        }
        if (this.tagName === "INPUT") {
            this.focus();
        }
    },
    _bindFocus: function (jqObj) {
        var _this = this;
        if (!jqObj.attr("_focus")) {
            jqObj.on("focus", _this._onfocus)
                .data("seft", _this).attr("tabindex", 0).attr("_focus", "true");
            jqObj.children().each(function () {
                _this._bindFocus($(this));
            });
        }
    },
    showColorPickerPanel: function (method, params) {
        this.ColorPickerPanel.show(this.currentClickBtn, {
            top: 5
        });
    },
    _createDropPanel: function (itemsArray, method, params, panelName, getItemHtmlFn) {
        var _this = this;
        var panel = $(dropDownControlHtml).appendTo(_getBody());
        panel.on("mouseenter", {
            seft: this
        }, this._dropDownControlMouseenter);
        panel.mouseleave(function () {
            _this._hideDropList();
            //console.log("panel.mouseout >>>>>>>panel.mouseout");
        });
        var wrap = panel.children(".k_edit_tools_drop_item_wrap");
        if (typeof itemsArray === "function") {
            itemsArray(wrap, params);
            _this._bindFocus(wrap);
        } else {
            var _click = function () {
                var $t = $(this);
                params[$t.data("_name")] = $t.data("_value");
                _this.edit.execute(method, params);
                if (method === "fontFamily" || method === "fontSize" || method === "fontTitle") {
                    _this.buttons[method].children("span").text($t.text());
                }
                clearTimeout(_this._hideDropListTimer);
                _this._hideDropListTimer = setTimeout(function () {
                    _this._hideDropList();
                }, 2000);
            };
            for (var i = 0, len = itemsArray.length; i < len; ++i) {
                var $html = getItemHtmlFn.call(wrap, itemsArray[i]);
                $html.appendTo(wrap);
                if (!$html.data("unbind_")) {
                    $html.click(_click).data("seft", _this);
                }
            }
            _this._bindFocus(wrap);
        }
        this.allPanels[panelName] = panel;
        return panel;
    },
    _showOrHidePanel: function ($panel, $btn, onShowFn) {
        if ($panel.css("display") === "none") {
            var ofs = $btn.offset();
            ofs.top = ofs.top + $btn.outerHeight() + 10;
            $panel.css(ofs).show();
            if (onShowFn) {
                onShowFn($panel);
            }
            this.tip.hide();
        } else {
            $panel.slideUp();
        }
    },
    showFontFamilyPanel: function (method, params, $btn) {
        if (!this.FontFamilyPanel) {
            this.FontFamilyPanel = this._createDropPanel(fontsFamilyMap, method, params, "FontFamilyPanel", function (it) {
                var $it = $("<div tabindex='0' style='font-family:" + it.v + "' class='k_edit_tools_drop_item'>" + it.txt + "</div>");
                $it.data("_value", it.v).data("_name", "font-family");
                return $it;
            });
        }
        this._showOrHidePanel(this.FontFamilyPanel, $btn);
    },
    showFontSizePanel: function (method, params, $btn) {
        if (!this.FontSizePanel) {
            this.FontSizePanel = this._createDropPanel(fontsMap, method, params, "FontSizePanel", function (it) {
                var $it = $("<div tabindex='0' style='font-size:" + it.v + "' class='k_edit_tools_drop_item'>" + it.txt + "</div>");
                $it.data("_value", it.v).data("_name", "font-size");
                return $it;
            });
        }
        this._showOrHidePanel(this.FontSizePanel, $btn);
    },
    showTitlePanel: function (method, params, $btn) {
        if (!this.FontTitlePanel) {
            this.FontTitlePanel = this._createDropPanel(titleArray, method, params, "FontTitlePanel", function (it) {
                var $it = $("<div tabindex='0' class='k_edit_tools_drop_item'>" + it.txt + "</div>").css(it.v);
                $it.data("_value", it.v).data("_name", "font-title");
                return $it;
            });
        }
        this._showOrHidePanel(this.FontTitlePanel, $btn);
    },
    showFontSpacePanel: function (method, params, $btn) {
        if (!this.FontSpacePanel) {
            var _this = this;
            var clickFn = function () {
                var $t = $(this);
                var id = $t.attr("id");
                var cmd, nextAll, user2;
                if (id && id === "_123") {
                    cmd = "reset";
                    nextAll = $t.nextAll();
                } else {
                    nextAll = $t.parent().nextAll();
                    if ($t.hasClass("reduce")) {
                        cmd = "reduce";
                    } else {
                        cmd = "accretion";
                    }
                }
                nextAll.find("._user2").each(function () {
                    var $s = $(this);
                    if ($s.children("i").hasClass("fa-ok-circled")) {
                        user2 = $s.attr("value");
                    }
                });
                params["cmd"] = cmd;
                params["user2"] = user2;
                _this.edit.execute(method, params);
            };
            this.FontSpacePanel = this._createDropPanel([{ i: 0 }, { i: 1 }, { i: 2 }], method, params, "FontSpacePanel", function (it) {
                var $it;
                if (it.i === 0) {
                    $it = $("<div id='_123' tabindex='0' class='k_edit_tools_drop_item'><i style='padding-right:6px;' class='fa fa-arrows-ccw'></i>" + eConfig.label.reset + "</div>");
                    $it.on("click", clickFn);
                } else if (it.i === 1) {
                    $it = $("<div tabindex='0' class='k_edit_tools_drop_item clearfix'><div title='" + eConfig.label.reduce + "' class='k_box_size reduce' style='width:50%;float:left;padding-right:5px;text-align:center;'><i class='fa fa-left'></i></div><div title='" + eConfig.label.accretion + "' style='width:50%;float:right;text-align:center' class='k_box_size'><i style='padding-left:5px;' class='fa fa-right'></i></div></div>");
                    $it.children("div").click(clickFn);
                } else {
                    $it = $("<div id='_000_' tabindex='0' class='k_edit_tools_drop_item'>应用于:<br/><span class='_user2' value='1' style='padding-right:3px'>选区<i class='fa fa-ok-circled'></i></span><span class='_user2' value='2'>段落<i class='fa fa-circle-empty'></i></span></div>");
                    $it.children("span").click(function () {
                        var $t = $(this);
                        var $i = $t.children("i");
                        if ($i.hasClass("fa-ok-circled")) {
                            $i.removeClass("fa-ok-circled").addClass("fa-circle-empty");
                            $t.siblings("span").children("i").removeClass("fa-circle-empty").addClass("fa-ok-circled");
                        } else {
                            $i.removeClass("fa-circle-empty").addClass("fa-ok-circled");
                            $t.siblings("span").children("i").removeClass("fa-ok-circled").addClass("fa-circle-empty");
                        }
                    });
                }
                $it.data("unbind_", true);
                return $it;
            });
        }
        this._showOrHidePanel(this.FontSpacePanel, $btn);
    },
    showFloatPanel: function (method, params, $btn) {
        if (!this.FloatPanel) {
            var _this = this;
            var clickFn = function () {
                var id = $(this).attr("id");
                if (id === '_f_txt') {
                    _this.edit.insertFloatText();
                } else {
                    _this.edit.insertFloatImg();
                }
                _this.FloatPanel.hide();
            };
            this.FloatPanel = this._createDropPanel([{ i: 0 }, { i: 1 }], method, params, "FontSpacePanel", function (it) {
                var $it;
                if (it.i === 0) {
                    $it = $("<div tabindex='0' id='_f_txt' class='k_edit_tools_drop_item'><i class='fa fa-doc-text' style='padding:2px 4px'></i>" + eConfig.label.insertFloatText + "</div>");
                } else if (it.i === 1) {
                    $it = $("<div tabindex='0' id='_f_img' class='k_edit_tools_drop_item'><i class='fa fa-file-image'  style='padding:2px 4px'></i>" + eConfig.label.insertFloatImg + "</div>");
                }
                $it.data("unbind_", true);
                $it.click(clickFn);
                return $it;
            });
        }
        this._showOrHidePanel(this.FloatPanel, $btn);
    },
    showTablePanel: function (method, params, $btn) {
        var _this = this;
        var tip;
        if (!this.TablePanel) {
            this.TablePanel = this._createDropPanel(function (wrap) {
                var $tab = $("<table  class='k_edit_table_set'></table>");
                for (var i = 0, len = 15; i < len; ++i) {
                    var $tr = $("<tr row='" + i + "'></tr>");
                    for (var j = 0, jlen = 15; j < jlen; ++j) {
                        $("<td col='" + j + "'></td>").appendTo($tr);
                    }
                    $tr.appendTo($tab);
                }
                $tab.appendTo(wrap);
                var tdArray = $tab.find("td");
                var col = 1;
                var row = 1;
                tdArray.mousemove(function () {
                    tdArray.removeClass("selectd");
                    var $td = $(this);
                    $td.addClass("selectd").prevAll().addClass("selectd");
                    col = parseInt($td.attr("col"));
                    var tr = $td.parent();
                    row = parseInt(tr.attr("row")) + 1;
                    tr.prevAll().each(function () {
                        $(this).children().each(function (i) {
                            var td = $(this);
                            td.addClass("selectd");
                            if (i >= col) {
                                return false;
                            }
                        });
                    });
                    tip.text(eConfig.insertTableTip.replace("x", row).replace("y", (col + 1)));
                }).click(function () {
                    params["col"] = col + 1;
                    params["row"] = row;
                    _this.edit.execute(method, params);
                    _this.TablePanel.hide();
                });
                tip = $("<div style='line-height:18px;text-align:center;font-size:12px;'></div>").appendTo(wrap);
            });
        }
        this.TablePanel.find(".selectd").removeClass("selectd");
        this._showOrHidePanel(this.TablePanel, $btn);
    },
    showParagraphPanel: function (method, params, $btn) {
        //修改为 弹窗方式，支持边框设置功能 2019-03-03
        this.edit.openParagrapWindow(method, params, $btn);
    },
    showOrderListPanel: function (method, params, $btn) {
        if (!this.OrderListPanel) {
            var _this = this;
            this.OrderListPanel = this._createDropPanel(function (wrap, params) {
                var list = [{
                    txt: eConfig.label.listNum,
                    v: "1"
                },
                {
                    "txt": eConfig.label.listLm,
                    v: "i"
                },
                {
                    txt: eConfig.label.listEn,
                    v: "a"
                },
                {
                    txt: eConfig.label.listNone,
                    v: "none"
                }];
                var ul = $('<ul style="list-style-type:none;"/>').appendTo(wrap);
                var clickFn = function () {
                    var $t = $(this);
                    var type = $t.attr("_type");
                    params["list-style-type"] = type;
                    _this.edit.execute(method, params);
                };
                for (var i = 0, len = list.length; i < len; ++i) {
                    var it = list[i];
                    var txt = it.txt;
                    if (it.v === "none") {
                        txt = "<i style='padding-right:6px;' class='fa icon-minus-sign'></i>" + txt;
                    } else if (it.v === "a") {
                        txt = "<i style='padding-right:6px;' class='fa icon-sort-by-alphabet'></i>" + txt;
                    } else if (it.v === "i") {
                        txt = "<i style='padding-right:6px;' class='fa icon-info'></i>" + txt;
                    } else {
                        txt = "<i style='padding-right:6px;' class='fa icon-sort-by-order'></i>" + txt;
                    }
                    var li = $("<li style='padding:2px 16px;' _type='" + it.v + "'>" + txt + "</li>").appendTo(ul);
                    li.click(clickFn);
                }
            }, method, params, "OrderListPanel");
        }
        this._showOrHidePanel(this.OrderListPanel, $btn);
    },
    showUnorderListPanel: function (method, params, $btn) {
        if (!this.UnorderListPanel) {
            var _this = this;
            this.UnorderListPanel = this._createDropPanel(function (wrap, params) {
                var list = [{
                    txt: eConfig.label.disc,
                    v: "disc"
                },
                {
                    "txt": eConfig.label.circle,
                    v: "circle"
                },
                {
                    txt: eConfig.label.square,
                    v: "square"
                },
                {
                    txt: eConfig.label.none,
                    v: "none"
                }
                ];
                var ul = $('<ul style="list-style-position:inside;padding:0;margin:0;"/>').appendTo(wrap);
                var clickFn = function () {
                    var $t = $(this);
                    var type = $t.css("list-style-type");
                    params["list-style-type"] = type;
                    _this.edit.execute(method, params);
                };
                for (var i = 0, len = list.length; i < len; ++i) {
                    var it = list[i];
                    var txt = it.txt;
                    if (it.v === "none") {
                        txt = "<i style='padding-right:6px;' class='fa icon-minus-sign'></i>" + txt;
                    }
                    var li = $("<li style='padding:2px 16px;list-style-type:" + it.v + "'>" + txt + "</li>").appendTo(ul);
                    li.click(clickFn);
                }
            }, method, params, "UnorderListPanel");
        }
        this._showOrHidePanel(this.UnorderListPanel, $btn);
    },
    showEmotion: function (method, params, $btn) {
        this.edit.openEmotionWindow(method, params, $btn);
    },
    showIcon: function (method, params, $btn) {
        this.edit.openIconWindow("insertIcon", params, $btn);
    },
    showCode: function (method, params, $btn) {
        this.edit.openCodeWindow(method, params, $btn);
    },
    showMap: function (method, params, $btn) {
        this.edit.openMapWindow(method, params, $btn);
    },
    showUploadVideo: function (method, params, $btn) {
        if (!window["videojs"]) {
            $B.error(eConfig.label.videoWarning);
            return;
        }
        this.edit.showUploadVideo(method, params, $btn);
    },
    showUploadFile: function (method, params, $btn) {
        this.edit.openInsertFileWindow(method, params, $btn);
    },
    showInsertImage: function (method, params, $btn) {
        this.edit.openInsertImageWindow(method, params, $btn);
    },
    showPhoneListPanel: function (method, params, $btn) {
        if (!this.PhoneListPanel) {
            var _this = this;
            var mobiles = eConfig.mobiles;
            this.PhoneListPanel = this._createDropPanel(mobiles, method, params, "PhoneListPanel", function (it) {
                var $it = $("<div tabindex='0' class='k_edit_tools_drop_item'>" + it.title + "</div>");
                $it.data("_value", it.size).data("_name", "phonesize").attr("title", it.size);
                return $it;
            });
        }
        this._showOrHidePanel(this.PhoneListPanel, $btn);

    },
    height: function () {
        return this.$wrap.outerHeight();
    }
};